const http = require('http');
const fs = require('fs');

let server = http.createServer((req, res) => {
    // 1.0 判断当前请求是 /getHero 同时请求方法是一个get
    // method是一个大写的GET或者POST
    let { url, method } = req;
    if (url === '/getHero' && method === 'GET') {
        let heroJson = fs.readFileSync('./db/data.json');

        res.setHeader('Content-Type', 'application/json');
        res.end(heroJson);
    } else {
        res.statusCode = 404;
        res.end('not found');
    }

});

server.listen(8003, () => {
    console.log('8003接口启动');
})